package com.example.product_practices.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.product_practices.domain.ChargeTb;
import com.example.product_practices.service.IChargeTbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xin.altitude.cms.common.entity.AjaxResult;
import xin.altitude.cms.common.entity.PageEntity;

import java.util.Arrays;

@RestController
@CrossOrigin
@RequestMapping("/chargeTb")
@Api(tags = "计费表")
public class ChargeTbController {
    @Autowired
    private IChargeTbService chargeTbService;

    @ApiImplicitParam(name = "chargeTb",value = "计费表",required = true,paramType = "query")
    @ApiOperation(value = "分页")
    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity, ChargeTb chargeTb) {
        return AjaxResult.success(chargeTbService.page(pageEntity.toPage(), Wrappers.lambdaQuery(chargeTb)));
    }

    @GetMapping("/list")
    public AjaxResult list(ChargeTb chargeTb) {
        return AjaxResult.success(chargeTbService.list(Wrappers.lambdaQuery(chargeTb)));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody ChargeTb chargeTb) {
        return AjaxResult.success(chargeTbService.save(chargeTb));
    }

    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody ChargeTb chargeTb) {
        return AjaxResult.success(chargeTbService.updateById(chargeTb));
    }

    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(chargeTbService.removeByIds(Arrays.asList(ids)));
    }

    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(chargeTbService.getById(id));
    }
}
